#coding=utf-8
import random
import os
import numpy as np
from time import sleep

path = os.getcwd()
bc = [
    "冷刃", "黎明神剑", "飞天御剑", "铁影阔剑", "沐浴龙血的剑", "以理服人", "黑缨枪", "魔导绪论", "讨龙英杰谭",
    "翡玉法球", "鸦羽弓", "神射手之誓", "弹弓"
]
pc = [
    "弓藏", "祭礼弓", "绝弦", "昭心", "祭礼残章", "流浪乐章", "匣里灭辰", "雨裁", "祭礼大剑", "钟剑",
    "匣里龙吟", "祭礼剑", "笛剑", "西风剑", "西风大剑", "西风长枪", "西风秘典", "西风猎弓", "嘉明", "夏沃蕾",
    "夏洛蒂", "菲米尼", "琳妮特", "绮良良", "卡维", "米卡", "瑶瑶", "珐露珊", "莱依拉", "坎蒂丝", "多莉",
    "柯莱", "鹿野院平藏", "久岐忍", "云堇", "五郎", "托马", "九条裟罗", "早柚", "烟绯", "罗莎莉亚", "辛焱",
    "迪奥娜", "诺艾尔", "菲谢尔", "丽莎", "凯亚", "雷泽", "重云", "凝光", "砂糖", "芭芭拉", "安柏", "香菱",
    "班尼特", "行秋", "北斗"
]
gc = [
    "琴", "莫娜", "刻晴", "七七", "迪卢克", "提纳里", "迪希雅", "天空之翼", "天空之卷", "天空之脊", "天空之傲",
    "天空之刃", "阿莫斯之弓", "四风原典", "和璞鸢", "狼的末路", "风鹰剑"
]
Varg = int(0)
Varp = int(0)
get = ""


def Initialize():
    global path
    global Varp
    global Varg
    with open(path + '\\Data\\get.txt', 'w') as gettxt:
        gettxt.write("")
    np.save(path + "\\Data\\P", Varp)
    np.save(path + "\\Data\\G", Varg)


def DrawCards():
    global path
    Varg = np.load(path + "\\Data\\G.npy")
    Varp = np.load(path + "\\Data\\P.npy")
    stars = 0
    color = int(float(random.randint(1, 100)))
    if Varg == 80 or color > 99:
        get = gc[random.randint(1, len(gc)) - 1]
        Varg = 0
        Varp = Varp + 1
        stars = 5
        print("\033[34m-\033[0m", end='', flush=True)
        sleep(0.2)
        print("\033[34m-\033[0m", end='', flush=True)
        sleep(0.2)
        print("\033[34m-\033[0m", end='', flush=True)
        sleep(0.2)
        print("\033[35m-\033[0m", end='', flush=True)
        sleep(0.5)
        print("\033[33m■\033[0m")
        sleep(0.3)
        print("\033[33m5 \033[0m", get)
    elif Varp == 9 or color > 95:
        get = pc[random.randint(1, len(pc)) - 1]
        Varg = Varg + 1
        Varp = 0
        stars = 4
        print("\033[34m-\033[0m", end='', flush=True)
        sleep(0.2)
        print("\033[34m-\033[0m", end='', flush=True)
        sleep(0.2)
        print("\033[34m-\033[0m", end='', flush=True)
        sleep(0.2)
        print("\033[35m-\033[0m", end='', flush=True)
        sleep(0.5)
        print("\033[35m■\033[0m")
        sleep(0.3)
        print("\033[35m4 \033[0m", get)
    else:
        get = bc[random.randint(1, len(bc)) - 1]
        Varp = Varp + 1
        Varg = Varg + 1
        stars = 3
        print("\033[34m-\033[0m", end='', flush=True)
        sleep(0.2)
        print("\033[34m-\033[0m", end='', flush=True)
        sleep(0.2)
        print("\033[34m-\033[0m", end='', flush=True)
        sleep(0.2)
        print("\033[34m-\033[0m", end='', flush=True)
        sleep(0.5)
        print("\033[34m■\033[0m")
        sleep(0.3)
        print("\033[34m3 \033[0m", get)

    np.save(path + "\\Data\\P", Varp)
    np.save(path + "\\Data\\G", Varg)
    with open(path + '\\Data\\get.txt', 'a') as gettxt:
        gettxt.write(str(stars) + " " + str(get))
        gettxt.write('\n')


def history():
    Varg = np.load(path + "\\Data\\G.npy")
    Varp = np.load(path + "\\Data\\P.npy")
    print("已有", Varp, "抽没出4星")
    print("已有", Varg, "抽没出5星")
    print("")
    with open(path + "\\Data\\get.txt", "r") as f:
        data = f.read()
        print(data)


print("这是一个原神抽卡模拟程序（卡池内容截止至4.5版本且仅为常驻池）")
print("由于这是一个模拟程序，所以概率不准确")
print("受限于个人技术，本程序未设置抽卡概率逐渐上升机制")
print("但有设置保底机制")
print("作为补偿，我为概率进行了平衡")
print("\033[34m三星\033[0m", "概率为95%")
print("\033[35m四星\033[0m", "概率为4%")
print("\033[33m五星\033[0m", "概率为1%")
print("\n")
xunhuan = 0
while xunhuan == 0:
    menu1 = ["1.初始化", "2.单抽", "3.十连", "4.自定义抽数", "5.查看历史", "6.退出"]
    for i in range(len(menu1)):
        print(menu1[i])
    choice = int(input("请输入命令序号："))
    if choice == 1:
        Initialize()
        print("已完成")
    elif choice == 2:
        DrawCards()
    elif choice == 3:
        for i in range(10):
            DrawCards()
    elif choice == 4:
        times = int(input("请输入抽数："))
        for i in range(times):
            DrawCards()
    elif choice == 5:
        history()
    elif choice == 6:
        xunhuan = 1
